package com.star.bookstore.product.controller;

import com.star.bookstore.common.utils.PageUtils;
import com.star.bookstore.common.utils.R;
import com.star.bookstore.product.entity.CommentEntity;
import com.star.bookstore.product.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author wuLiFei
 * @email wuLiFei@gmail.com
 * @date 2021-03-07 13:57:20
 */
@RestController
@RequestMapping("product/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("information:comment:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = commentService.queryPage(params);

        return R.ok().put("page", page);
    }

    //由分类id查询对应的评论
    @RequestMapping("/list/{categoryId}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable Long categoryId){


        PageUtils page = commentService.queryPage(params,categoryId);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{comId}")
    //@RequiresPermissions("information:comment:info")
    public R info(@PathVariable("comId") Long comId){
		CommentEntity comment = commentService.getById(comId);

        return R.ok().put("comment", comment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("information:comment:save")
    public R save(@RequestBody CommentEntity comment){
		commentService.save(comment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("information:comment:update")
    public R update(@RequestBody CommentEntity comment){
		commentService.updateById(comment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("information:comment:delete")
    public R delete(@RequestBody Long[] comIds){
		commentService.removeByIds(Arrays.asList(comIds));

        return R.ok();
    }

}
